package com.glory.eapequipmentmonitor.activity;

import android.content.Intent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.glory.eapequipmentmonitor.R;
import com.pda.platform.ui.ui_pdaplatform.activity_public.FreeUI_QRCodeActivity;
import com.pda.platform.ui.ui_pdaplatform.base.FreeUI_BaseActivity;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_CommonCallback;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_TextCallback;
import com.pda.platform.ui.ui_pdaplatform.dialog.FreeUI_GeneralFragmentDialog;
import com.pda.platform.ui.ui_pdaplatform.dialog.FreeUI_GeneralPop;
import com.pda.platform.ui.ui_pdaplatform.entity.FreeUI_AddViewEntity;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_DialogUtils;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_PopUtils;
import com.pda.platform.ui.ui_pdaplatform.view.FreeUI_ClearEditText;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class EqpRepairActivity extends FreeUI_BaseActivity {


    public static final int RESULT_SCAN = 1101;
    @BindView(R.id.tvUser)
    TextView tvUser;
    @BindView(R.id.ivScan)
    ImageView ivScan;
    @BindView(R.id.tvEqpId)
    TextView tvEqpId;
    @BindView(R.id.tvLotTitle)
    TextView tvLotTitle;
    @BindView(R.id.tvDepotCode)
    TextView tvDepotCode;
    @BindView(R.id.ivArrow)
    ImageView ivArrow;
    @BindView(R.id.llCode)
    LinearLayout llCode;
    @BindView(R.id.etRemark)
    FreeUI_ClearEditText etRemark;
    @BindView(R.id.tvBtnOne)
    TextView tvBtnOne;
    @BindView(R.id.tvBtnTwo)
    TextView tvBtnTwo;
    @BindView(R.id.tvBtnThree)
    TextView tvBtnThree;
    @BindView(R.id.flMain)
    FrameLayout flMain;
    @BindView(R.id.llMain)
    LinearLayout llMain;
    private FreeUI_GeneralFragmentDialog freeUI_generalFragmentDialog;
    private FreeUI_GeneralPop codePop;
    private List<String> codeList;

    @OnClick({R.id.ivScan, R.id.tvBtnOne, R.id.tvBtnTwo, R.id.tvBtnThree, R.id.llCode})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.ivScan:
                startActivityForResult(new Intent(EqpRepairActivity.this, FreeUI_QRCodeActivity.class), RESULT_SCAN);
                break;
            case R.id.llCode:
                if (codePop == null) {
                    codePop = FreeApi_PopUtils.getNormalPop(getApplicationContext(), llCode.getWidth(), codeList, ivArrow, new FreeUI_TextCallback() {
                        @Override
                        public void onSuccess(String s) {
                            tvDepotCode.setText(s);
                        }
                    });
                }
                if (codePop.isShowing()) {
                    codePop.dismiss();
                } else {
                    FreeApi_PopUtils.setArrowShow(ivArrow);
                    codePop.showAsDropDown(llCode, 0, 0);
                }

                break;
            case R.id.tvBtnOne:
                freeUI_generalFragmentDialog = FreeApi_DialogUtils.getConfirmAndCancelDialog(getApplicationContext(), "确定要开始维修吗",
                        new FreeUI_CommonCallback() {
                            @Override
                            public void onSuccess() {
                                showToast("开始成功", true);
                                freeUI_generalFragmentDialog.dismiss();
                            }
                        }, new FreeUI_CommonCallback() {
                            @Override
                            public void onSuccess() {
                                freeUI_generalFragmentDialog.dismiss();
                            }
                        });
                freeUI_generalFragmentDialog.show(getSupportFragmentManager(), "freeUI_generalFragmentDialog");
                break;
            case R.id.tvBtnTwo:
                freeUI_generalFragmentDialog = FreeApi_DialogUtils.getConfirmAndCancelDialog(getApplicationContext(), "确定要维修完成吗",
                        new FreeUI_CommonCallback() {
                            @Override
                            public void onSuccess() {
                                showToast("维修完成成功", true);
                                freeUI_generalFragmentDialog.dismiss();
                            }
                        }, new FreeUI_CommonCallback() {
                            @Override
                            public void onSuccess() {
                                freeUI_generalFragmentDialog.dismiss();
                            }
                        });
                freeUI_generalFragmentDialog.show(getSupportFragmentManager(), "freeUI_generalFragmentDialog");
                break;
        }
    }


    @Override
    protected int getLayoutResId() {
        return R.layout.activity_eqp_repair;
    }

    @Override
    protected void initView() {
        tvBtnOne.setText("开始维修");
        tvBtnTwo.setText("维修完成");
        tvBtnThree.setVisibility(View.GONE);
    }

    @Override
    protected void initData() {
        requestCode();
    }

    private void requestCode() {
        codeList = new ArrayList<>();
        for (int i = 0; i < 8; i++) {
            codeList.add("T-CODE" + i);
        }
        tvDepotCode.setText(codeList.get(0));
    }

    @Override
    protected FreeUI_AddViewEntity getBaseEntity() {
        freeUI_titleView.setTitle("设备维修");
        return new FreeUI_AddViewEntity("header", llMain);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
        if (requestCode == RESULT_SCAN && resultCode == RESULT_OK) {
            if (intent != null) {
                String str = intent.getStringExtra("barCode");
                tvUser.setText(str);
            }
        }
    }
}

